﻿namespace MhAdmin.System;

/// <summary>
/// 编码规则控制器
/// </summary>
[ApiDescriptionSettings("System", Tag = "编码规则")]
[Route("/dev/rules")]
[RolePermission]
public class RulesController : IDynamicApiController
{
    private readonly IRulesService _rulesService;

    public RulesController(IRulesService rulesService
    )
    {
        this._rulesService = rulesService;
    }

    #region Get请求

    /// <summary>
    /// 编码规则分页查询
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("page")]
    [DisplayName("编码规则分页查询")]
    public async Task<dynamic> Page([FromQuery] RulesPageInput input)
    {
        return await _rulesService.Page(input);
    }

    /// <summary>
    /// 编码规则列表查询
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("list")]
    [DisplayName("编码规则列表查询")]
    public async Task<dynamic> List([FromQuery] RulesPageInput input)
    {
        return await _rulesService.List(input);
    }

    /// <summary>
    /// 编码规则详情
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("detail")]
    [DisplayName("编码规则详情")]
    public async Task<dynamic> Detail([FromQuery] BaseIdInput input)
    {
        return await _rulesService.Detail(input);
    }


    /// <summary>
    /// 测试编码
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("testCode")]
    [DisplayName("测试编码")]
    public async Task<dynamic> TestCode([FromQuery] RulesTestInput input)
    {
        return await _rulesService.TestCode(input);
    }
    #endregion Get请求

    #region Post请求

    /// <summary>
    /// 添加编码规则
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("add")]
    [DisplayName("添加编码规则")]
    public async Task Add([FromBody] RulesAddInput input)
    {
        await _rulesService.Add(input);
    }

    /// <summary>
    /// 修改编码规则
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("edit")]
    [DisplayName("修改编码规则")]
    public async Task Edit([FromBody] RulesEditInput input)
    {
        await _rulesService.Edit(input);
    }

    /// <summary>
    /// 删除编码规则
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("delete")]
    [DisplayName("删除编码规则")]
    public async Task Delete([FromBody] List<BaseIdInput> input)
    {
        await _rulesService.Delete(input);
    }

   

    #endregion Post请求
}
